package com.mf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mf.entity.UserDayHistory;
import com.mf.mapper.UserDayHistoryMapper;
import com.mf.service.IUserDayHistoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mf.vo.UserDayHistoryVo;
import io.micrometer.common.util.StringUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 每天用户金额变动记录历史 服务实现类
 * </p>
 *
 * @author mf
 * @since 2024-05-19
 */
@Service
public class UserDayHistoryServiceImpl extends ServiceImpl<UserDayHistoryMapper, UserDayHistory> implements IUserDayHistoryService {
    @Resource
    private UserDayHistoryMapper userDayHistoryMapper;
    @Override
    public Page<UserDayHistory> findUserDayHistory(UserDayHistoryVo userDayHistoryVo) {
        final LambdaQueryWrapper<UserDayHistory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserDayHistory::getUserId, userDayHistoryVo.getUserId());

        // 时间范围查询
        if (StringUtils.isNotEmpty(userDayHistoryVo.getStart()) && StringUtils.isNotEmpty(userDayHistoryVo.getEnd())) {
            queryWrapper.between(UserDayHistory::getDate, userDayHistoryVo.getStart(), userDayHistoryVo.getEnd());
        }

        Page<UserDayHistory> page = new Page<>(userDayHistoryVo.getPageNum(), userDayHistoryVo.getPageSize());
        return userDayHistoryMapper.selectPage(page, queryWrapper);
    }
}
